varying vec3 pos,l,n,v,h;
varying vec2 texCoord;
uniform sampler2D envMap; 
uniform sampler2D leaf; 
varying bool reverse;
uniform vec3 eyePos;
 
float module(vec3 a, vec3 b) {
    vec3 c = a - b;
    return sqrt(c.x*c.x + c.y*c.y + c.z*c.z);
}   
void main(void) {
   float fr = module(eyePos,pos);
   float start = 0.0;
   float end = 1000.0;
   float summar = min(max( dot(normalize(l), vec3(0.0,0.0,1.0)), 0.1 ),0.5);
   if(fr > end) { 
   		gl_FragColor = vec4(summar);
   		return;
   } 
   float  r;
   r =  max(0.2,dot(l, n));
   vec4 color = texture2D(leaf,texCoord);
   float transparency = color.w;
   if(fr > 150.0 && fr < 250.0) transparency *= (250.0 - fr)/100.0;
   if(fr >= 250.0) transparency = 0.0; 
   gl_FragColor = color*r;
   gl_FragColor.w = transparency;
      if(pos.z > 0.0 && fr > start) {
    fr = 1.0/(1.0 - (fr/end));
    gl_FragColor.x = summar + (gl_FragColor.x - summar)/fr;
    gl_FragColor.y = summar + (gl_FragColor.y - summar)/fr;
    gl_FragColor.z = summar + (gl_FragColor.z - summar)/fr;
    }
}